/**
 * Generate code from /{{projectName}}-core/src/main/java/{{packageName}}/core/{{modules}}/filter/{{entities@SQL}}SearchContext.java.hbs
 */
package cn.ibizlab.core.authorization.filter;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import java.util.*;
import java.io.Serializable;
import com.fasterxml.jackson.annotation.*;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import lombok.experimental.Accessors;
import lombok.extern.slf4j.Slf4j;
import com.alibaba.fastjson.annotation.JSONField;

import org.apache.commons.lang3.StringUtils;
import org.springframework.data.annotation.Transient;
import org.springframework.util.ObjectUtils;
import cn.ibizlab.util.filter.QueryWrapperContext;
import cn.ibizlab.util.filter.QueryFilter;
import cn.ibizlab.util.enums.Entities;
import cn.ibizlab.core.authorization.domain.SysRoleMember;

/**
 * 关系型数据实体[SysRoleMember] 查询条件对象
 *
 * @author generator
 */
@Slf4j
@Getter
@Setter
@NoArgsConstructor
@Accessors(chain = true)
@ApiModel("系统角色成员查询条件对象")
public class SysRoleMemberSearchContext extends QueryWrapperContext<SysRoleMember> {

    /**
     * 标识EQ
     */
    @JsonProperty("n_id_eq")
    @JSONField(name = "n_id_eq")
    @ApiModelProperty("标识EQ")
    private String idEQ;

    /**
     * 系统角色标识EQ
     */
    @JsonProperty("n_role_id_eq")
    @JSONField(name = "n_role_id_eq")
    @ApiModelProperty("系统角色标识EQ")
    private String roleIdEQ;

    /**
     * 成员类型EQ
     */
    @JsonProperty("n_member_type_eq")
    @JSONField(name = "n_member_type_eq")
    @ApiModelProperty("成员类型EQ")
    private String memberTypeEQ;

    /**
     * 用户组/人员标识EQ
     */
    @JsonProperty("n_member_uid_eq")
    @JSONField(name = "n_member_uid_eq")
    @ApiModelProperty("用户组/人员标识EQ")
    private String memberUidEQ;

    /**
     * 用户组/人员标识IN
     */
    @JsonProperty("n_member_uid_in")
    @JSONField(name = "n_member_uid_in")
    @ApiModelProperty("用户组/人员标识IN")
    private String memberUidIN;

    /**
     * 成员名称EQ
     */
    @JsonProperty("n_member_name_eq")
    @JSONField(name = "n_member_name_eq")
    @ApiModelProperty("成员名称EQ")
    private String memberNameEQ;

    /**
     * 成员名称LIKE
     */
    @JsonProperty("n_member_name_like")
    @JSONField(name = "n_member_name_like")
    @ApiModelProperty("成员名称LIKE")
    private String memberNameLIKE;

    /**
     * 成员分组标识EQ
     */
    @JsonProperty("n_member_group_id_eq")
    @JSONField(name = "n_member_group_id_eq")
    @ApiModelProperty("成员分组标识EQ")
    private String memberGroupIdEQ;

    /**
     * 部门标识EQ
     */
    @JsonProperty("n_department_id_eq")
    @JSONField(name = "n_department_id_eq")
    @ApiModelProperty("部门标识EQ")
    private String departmentIdEQ;

    /**
     * 组织机构标识EQ
     */
    @JsonProperty("n_organization_id_eq")
    @JSONField(name = "n_organization_id_eq")
    @ApiModelProperty("组织机构标识EQ")
    private String organizationIdEQ;

    /**
     * 系统角色名称LIKE
     */
    @JsonProperty("n_role_name_like")
    @JSONField(name = "n_role_name_like")
    @ApiModelProperty("系统角色名称LIKE")
    private String roleNameLIKE;

    /**
     * 角色标记LIKE
     */
    @JsonProperty("n_role_authority_like")
    @JSONField(name = "n_role_authority_like")
    @ApiModelProperty("角色标记LIKE")
    private String roleAuthorityLIKE;

    /**
     * 系统标识EQ
     */
    @JsonProperty("n_deploy_system_id_eq")
    @JSONField(name = "n_deploy_system_id_eq")
    @ApiModelProperty("系统标识EQ")
    private String deploySystemIdEQ;

    @Override
    public void setContextParentKey(Serializable contextParentKey) {
        super.setContextParentKey(contextParentKey);
        if(Entities.SYS_COMMON_NAME.equals(this.getContextParentEntity())&&contextParentKey!=null)
            this.getFilter().eq("member_uid",contextParentKey);
        if(Entities.SYS_ROLE.equals(this.getContextParentEntity())&&contextParentKey!=null)
            this.getFilter().eq("role_id",contextParentKey);
    }

    @Override
    public void setQuery(String query) {
        this.query=query;
        if(!ObjectUtils.isEmpty(query))
            this.getFilter().and(QueryFilter.createQuery().or(QueryFilter.createQuery().like("id",query),QueryFilter.createQuery().like("member_name",query),QueryFilter.createQuery().like("member_dn",query)));
    }

    @JsonIgnore
    @JSONField(serialize = false)
    @Transient
    @Override
    public QueryWrapper<SysRoleMember> getSelectCond() {
        QueryWrapper<SysRoleMember> queryWrapper = super.getSelectCond();
        return queryWrapper;
    }
}